﻿using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
using SouthAfrica.PresentationModels;
using SouthAfrica.Infrastructure;
using SouthAfrica.Views;

namespace SouthAfrica.Modules.Case
{
    public class CaseModule :IModule
    {
        private readonly IUnityContainer container;
        private readonly IRegionManager regionManager;

        public CaseModule(IUnityContainer container, IRegionManager regionManager)
        {
            this.container = container;
            this.regionManager = regionManager;
        }

        #region IModule Members

        public void Initialize()
        {
            RegisterViewsAndServices();

            this.regionManager.RegisterViewWithRegion(RegionNames.CaseMainRegion, () => this.container.Resolve<ICaseQueryPresentationModel>().View);
            this.regionManager.RegisterViewWithRegion(RegionNames.CaseMainRegion, () => this.container.Resolve<ICaseCreatePresentationModel>().View);

        }

        protected void RegisterViewsAndServices()
        {            
           container.RegisterType<ICaseQueryView, CaseQueryView>();
           container.RegisterType<ICaseQueryPresentationModel, CaseQueryPresentationModel>();
           container.RegisterType<ICaseCreateView, CaseCreateView>();
           container.RegisterType<ICaseCreatePresentationModel, CaseCreatePresentationModel>();
        }

        #endregion
    }
}
